package main

import (
	"gitee.com/lv-forever/open-ai-api/api"
	"gitee.com/lv-forever/open-ai-api/config"
	"github.com/gin-gonic/gin"
	"net/http"
	"time"
)

func main() {
	// Auto verify key
	duration := 24 * time.Hour
	ticker := time.NewTicker(duration)
	defer ticker.Stop()
	go func() {
		for range ticker.C {
			config.AutoVerifyKey()
		}
	}()

	router := gin.Default()

	// Ask a question
	router.POST("/ask", api.ASK)

	// Add a OpenAI-key
	router.GET("/addkey", api.AddAPIKey)

	// Add a health endpoint
	router.GET("/health", func(c *gin.Context) {
		c.String(http.StatusOK, "OK")
	})

	// config run config
	configs := config.LoadConfig()
	port := ":" + configs.HttpPort

	gin.SetMode(configs.GinMode)
	router.Run(port)
}
